package com.lakeworks.web.controller.core;

import com.github.pagehelper.PageInfo;
import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.domain.OprShipment;
import com.lakeworks.service.IOprShipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 出厂单Controller
 *
 * @author lake
 * @date 2023-02-08
 */
@Slf4j
@RestController
@RequestMapping("/shipment")
public class OprShipmentController extends BaseController {

    @Autowired
    private IOprShipmentService oprShipmentService;

    @GetMapping("/test")
    public String test() {
        return "哈哈";
    }

    /**
     * 获取快递面单
     */
    @GetMapping("/{shipmentId}/label")
    public AjaxResult getLabel(@PathVariable Long shipmentId) {
        OprShipment oprShipment = oprShipmentService.selectOprShipmentById(shipmentId);
        if (oprShipment == null)
            return error("出厂单不存在");
        log.info("获取快递面单，shipmentId：[{}]，label：[{}]",shipmentId,oprShipment.getLabel());

        return success().put("label", oprShipment.getLabel());
    }


    /**
     * 获取出厂单列表
     */
    @GetMapping("/list")
    @ResponseBody
    public AjaxResult shipments(OprShipment oprShipment) {
        List<OprShipment> list = oprShipmentService.selectShipmentList(oprShipment);
        return AjaxResult.success(new PageInfo<>(list));
    }



    /**
     * 获取拣货单出厂单列表
     */
    @GetMapping("/shipments")
    @ResponseBody
    public AjaxResult list(OprShipment oprShipment) {
        List<OprShipment> list = oprShipmentService.selectOprShipmentList(oprShipment);
        return AjaxResult.success(new PageInfo<>(list));
    }

    /**
     * 生成拣货单
     */
    @PostMapping("/picking")
    @ResponseBody
    public AjaxResult picking(@RequestBody List<Long> ShipmentIds) {
        return oprShipmentService.picking(ShipmentIds);
    }

    /**
     * 出厂单修改已出厂
     */
    @PostMapping("/outfactory")
    @ResponseBody
    public AjaxResult outFactory(Long id) {
        return AjaxResult.success();
    }

}
